package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuSaveInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//http://api.gmall.com/admin/product/list/{page}/{limit}
@RestController
@RequestMapping("admin/product")
public class SkuController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 商品上架
     * @param skuId
     * @return
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        skuInfoService.onSale(skuId);
        return Result.ok();
    }

    /**
     * 商品下架
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        skuInfoService.cancelSale(skuId);
        return Result.ok();
    }


    @ApiOperation("sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result skuInfoList(@PathVariable("page") Long pn, @PathVariable("limit") Long ps){

        Page<SkuInfo> page = skuInfoService.page(new Page<>(pn, ps));

        return Result.ok(page);
    }

//    http://api.gmall.com/admin/product/saveSkuInfo

    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuSaveInfoVo vo){
        skuInfoService.saveSkuInfo(vo);
        return Result.ok();

    }
}
